package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

type Banner struct {
	ID            string `json:"id" gorm:"primaryKey;column:id;type:bigint"`
	Position      int    `json:"position" gorm:"column:position;type:int;comment:banner的位置,1-首页 2-我的 3-首页小图"`
	Name          string `json:"name" gorm:"column:name;type:string;size:20;comment:banner名称"`
	Status        int    `json:"status" gorm:"column:status;type:int;size:8;comment:状态，1-进行中 2-未开始 3-已结束"`
	StartTime     int64  `json:"start_time" gorm:"column:start_time;type:bigint;comment:开始时间"`
	EndTime       int64  `json:"end_time" gorm:"column:end_time;type:bigint;comment:结束时间"`
	Image         string `json:"image" gorm:"column:image;type:varchar(100);comment:banner图片"`
	LinkType      *int   `json:"link_type" gorm:"column:link_type;type:int;size:8;default:0;comment:连接类型,1-内部连接 2-外部连接"`
	OnlineEventID string `json:"online_event_id" gorm:"column:online_event_id;type:bigint;comment:活动id"`
	Link          string `json:"link" gorm:"column:link;type:string;size:200;comment:外部商品链接"`
	CreatedAt     int64  `json:"created_at" gorm:"column:created_at;autoCreateTime;type:int;size:64;index:idx_createdAt;comment:创建时间"`
	UpdatedAt     int64  `json:"updated_at" gorm:"column:updated_at;type:int;size:64"`
}

func (Banner) TableName() string {
	return "banner"
}

// BeforeCreate 自增id
func (m *Banner) BeforeCreate(tx *gorm.DB) (err error) {
	if m.ID != "" {
		return nil
	}
	// 用户id为空时，自动添加用户id
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	m.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &Banner{})
}
